package com.woniuxy.producer;

import com.woniuxy.util.RabbitmqConst;
import org.springframework.amqp.AmqpException;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessagePostProcessor;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * @author dingpf
 * @version 1.0
 * @description
 * @create 2025/5/6 14:37
 */
@Component
public class DelayProducer {

    @Resource
    private RabbitTemplate rabbitTemplate;

    public void send(String msg,String routekey,Integer TTL){
        rabbitTemplate.convertAndSend(RabbitmqConst.DELAY_EXCHANGE, routekey, msg, new MessagePostProcessor() {
            @Override
            public Message postProcessMessage(Message message) throws AmqpException {
                message.getMessageProperties().setDelay(TTL);
                return message;
            }
        });
    }
}
